<?php
/**
 * Errors from whole site are parsed here
 *
 * TODO: Make OO version of this file
 * @package site
 * @author Mundusnovis studio
 * @version 1.0
 * @copyright 2007 Mundusnovis studio
 * @site http://mundusnovis.info
 */

// Requiring necessary files
require_once('config.php');
require_once('internal/strings.func.php');
global $mae;
require_once('lang/'.$mae['site_lang'].'.php');

/* function resolve_error(string $path)
 * Resolves the error content from the language path
 */
function reserror($path) {
        global $lang;
        $keys = explode('/', $path);

        if (empty($path)) return false;

        $eval_str = 'return $lang';
        for ($i=0; $i<count($keys); $i++) $eval_str .= "['".$keys[$i]."']";
        $eval_str .= ';';

        return eval($eval_str);
}

$code = $_GET['code'];
$error = reserror($_GET['error']);
// If file does not exists, change "redir" variable's value
$redir = (file_exists(basename($_GET['redir']))) ? $_GET['redir'] : 'javascript:history.back();';

// errorcode parsing
if ($code != "PHP") $code = (int)$code;
if (!$code) $code = "none";
if (($code == "PHP") && !$error) $error = $lang['error']['errors']['PHP'];

// Header displaying according to the error code
if ($code!='none' && $code!='PHP') header(' ', true, $code);

$lang['error']['errors']['PHP'] = $error;
if (empty($lang['error']['errortypes'][$code])) {
	$lang['error']['errortypes'][$code] = $lang['error']['unknown']['errortypes'];
	$lang['error']['errors'][$code] = str_replace('*', $code, $lang['error']['unknown']['errortypes']);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/2001/REC-xhtml11-20010531/DTD/xhtml11-flat.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mae. - <?php echo $lang['errortext']; ?></title>
<link rel="stylesheet" href="error.css" type="text/css" />
</head>
<body>
<div id="container">
 <div id="info">
  <div id="header"><img src="images/transparent_mae.png" alt="mae." /></div>
  <h2><?php echo $lang['error']['errortypes'][$code]; ?></h2>
  <div id="text"><?php echo $lang['error']['errors'][$code]; ?><br /><a href="<?php echo $redir.'">'.$lang['back'];?></a></div>
 </div>
 <div id="code"><div id="no"><?php echo $code; ?></div></div>
</div>
</body>
</html>
